<template>
  <view w-full pa-40rpx box-border>
    <nut-swiper height="360rpx" :pagination-visible="true" auto-play="5000">
      <nut-swiper-item v-for="(item, index) in swiperList" :key="index">
        <image mode="aspectFill" w-670rpx h-280rpx rounded-20rpx :src="item.img" />
      </nut-swiper-item>
    </nut-swiper>
    <view w-full box-border flex justify-around items-center my-60rpx>
      <view
        v-for="(item, index) in actions"
        :key="index"
        flex
        flex-col
        justify-center
        items-center
        @click="$navigateTo(item.url)">
        <image :src="'/pages/exam/static/' + item.img + '.png'" w-60rpx h-60rpx></image>
        <view mt-20rpx text-24rpx>{{ item.title }}</view>
      </view>
    </view>
    <view
      v-for="(item, index) in examActions"
      :key="index"
      bg-white
      rounded-20rpx
      px-30rpx
      py-40rpx
      mb-30rpx
      box-border
      w-full
      flex
      justify-between
      items-center
      @click="$navigateTo(item.url)">
      <view flex items-center>
        <image :src="'/pages/exam/static/' + item.img + '.png'" w-140rpx h-140rpx mr-30rpx></image>
        <view flex flex-col justify-center>
          <view text-32rpx font-500 mb-20rpx>{{ item.title }}</view>
          <view text="#7D7D7D" text-24rpx>{{ item.desc }}</view>
        </view>
      </view>
      <image w-40rpx h-40rpx src="/pages/exam/static/right.png"></image>
    </view>
  </view>
  <tabbar></tabbar>
</template>

<script setup lang="ts">
import { selectExamImg } from '@/api/exam'
import { onLoad, onShow } from '@dcloudio/uni-app'
import { useTabbarStore } from '@/store'
const tabbarStore = useTabbarStore()
const tabbarList = tabbarStore.tabbarList.map((i) => i.linkUrl)
const pages = getCurrentPages() // 获取当前页面栈
const currentPage = pages[pages.length - 1] // 当前页面
const currentPath = `/${currentPage.route}` // 获取当前页面路径
const curPageIsHaveTab = computed(() => {
  return tabbarList.includes(currentPath)
})
interface SwiperItem {
  img: string
}
const swiperList = ref<SwiperItem[]>([])

function getSwiper() {
  selectExamImg().then((res: any) => {
    swiperList.value = res.data.result
  })
}

const actions = ref([
  { title: '顺序练习', url: '/pages/exam/exer', img: 'action_1' },
  { title: '专题练习', url: '/pages/exam/topicExer?type=1', img: 'action_2' },
  { title: '考试记录', url: '/pages/exam/examList?type=9', img: 'action_3' },
  { title: '错题记录', url: '/pages/exam/errorRecord', img: 'action_4' }
])

const examActions = ref([
  { title: '模拟考试', desc: '模拟考试检验近期学习成果', url: '/pages/exam/examList?type=1', img: 'moni' },
  { title: '综合考试', desc: '综合类题库考试', url: '/pages/exam/examList?type=2', img: 'zonghe' },
  { title: '专题考试', desc: '专题类题库考试', url: '/pages/exam/topicExer?type=2', img: 'zhuanti' }
])

onMounted(() => {})
onLoad((options: any) => {
  if (tabbarStore.activeTabName && curPageIsHaveTab.value) {
    uni.setNavigationBarTitle({
      title: tabbarStore.activeTabName
    })
  }
  if (options.functionName) {
    uni.setNavigationBarTitle({
      title: options.functionName
    })
  }

  getSwiper()
})
</script>
<style>
page {
}
</style>
<style scoped lang="scss"></style>
